package com.eternal.widget.guqiang;

import androidx.databinding.BindingAdapter;
import androidx.databinding.InverseBindingAdapter;
import androidx.databinding.InverseBindingListener;
import android.view.View;

/**
 * Created by Administrator
 * On 2020/5/8
 * Description:
 * @author Administrator
 */
public class SingleProgressBarAdapter {

    @BindingAdapter(value = {"progress"})
    public static void setProgress(SingleProgressBar bar, int value){
        if(bar.getProgress()!=value){
            bar.setShowText(value);
        }
    }

    @InverseBindingAdapter(attribute = "progress", event = "progressAttrChanged")
    public static int getProgress(SingleProgressBar bar){
        return bar.getProgress();
    }

    @BindingAdapter(value = {"progressAttrChanged"})
    public static void progressAttrChanged(SingleProgressBar bar, final InverseBindingListener listener){
        bar.setOnChangeListener(new SingleProgressBar.OnChangeListener() {
            @Override
            public void onDown() {

            }

            @Override
            public void onEnd() {

            }

            @Override
            public void onChange(View view, int size) {
                listener.onChange();
            }
        });
    }
}
